<?php
class Etian_Controllers_Helpers_ViewRenderer
    extends Zend_Controller_Action_Helper_ViewRenderer
{
    /**
     * Name of layout script to render. Defaults to 'tplSite.php'.
     *
     * @var string
     */
    protected $_mainScript = 'main.tpl.php';
    protected $_headerScript = 'header.tpl.php';
    protected $_footerScript = 'footer.tpl.php';
    
  
    
    /**
     * Constructor
     * 
     * @param  Zend_View_Interface $view 
     * @param  array $options 
     * @return void
     */
    public function __construct(Zend_View_Interface $view = null, 
                                array $options = array())
    {
        parent::__construct($view, $options);
    }
    
    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
        //the path MUST be appended here, otherwise it will be too late OR too early
        $this->view->addHelperPath
        	('C:\Program Files\Apache Software Foundation\Apache2.2\apps\etian\controllers\Views\Helpers', 
				'Etian_Controllers_Views_Helpers');
        return $this;
    }
    /**
     * Set the layout script to be rendered.
     *
     * @param string $script
     */
  
    public function setMainScript($script)
    {
        $this->_mainScript = $script;
    }
    
    public function setHeaderScript($script)
    {
        $this->_headerScript = $script;
    }

    public function setFooterScript($script)
    {
        $this->_footerScript = $script;
    }
    /**
     * Retreive the name of the layout script to be rendered.
     *
     * @return string
     */
    public function getMainScript()
    {
        return $this->_mainScript;
    }
    
    public function getHeaderScript()
    {
        return $this->_headerScript;
    }

    public function getFooterScript()
    {
        return $this->_footerScript;
    }
    
    /**
     * Render the action script and assign the view for use
     * in the layout script. Render the layout script and append
     * to the Response's body.
     *
     * @param string $script
     * @param string $name
     */
    public function renderScript($script, $name = null)
    {
        $this->view->imgUrl = $this->_request->getBaseUrl();        					
		$this->view->assign('role',$this->getRequest()->getParam('role'));
		
				
        if (null === $name) {
            $name = $this->getResponseSegment();
        }
        
        // assign action scripts names to view.
		$_tplScripts = array();
		$_tplScripts[0] = $this->getHeaderScript();
		$_tplScripts[1] = $script;
		$_tplScripts[2] = $this->getFooterScript();
		
        $this->view->actionScript = $_tplScripts;
        
        $mainScript = $this->getMainScript();
        
        $mainContent = $this->view->render($mainScript);
        $this->getResponse()->appendBody($mainContent, $name);
              
        $this->setNoRender();
    
    }
}
?>